package com.ruoyi.reply.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.reply.domain.TbReply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.reply.service.ITbReplyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 答辩Controller
 *
 * @author sun
 * @date 2023-01-30
 */
@RestController
@RequestMapping("/reply")
public class TbReplyController extends BaseController
{
    @Autowired
    private ITbReplyService tbReplyService;

    /**
     * 查询答辩列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbReply tbReply)
    {
        startPage();
        List<TbReply> list = tbReplyService.selectTbReplyList(tbReply);
        return getDataTable(list);
    }

    /**
     * 导出答辩列表
     * adsfasdfffsdff
     */
    @Log(title = "答辩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbReply tbReply)
    {
        List<TbReply> list = tbReplyService.selectTbReplyList(tbReply);
        ExcelUtil<TbReply> util = new ExcelUtil<TbReply>(TbReply.class);
        util.exportExcel(response, list, "答辩数据");
    }

    /**
     * 获取答辩详细信息
     */
    @GetMapping(value = "getReplyById/{replyId}")
    public AjaxResult getInfo(@PathVariable("replyId") Integer replyId)
    {
        return success(tbReplyService.selectTbReplyByReplyId(replyId));
    }

    /**
     * 新增答辩
     */
    @Log(title = "答辩", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TbReply tbReply)
    {
        return toAjax(tbReplyService.insertTbReply(tbReply));
    }

    /**
     * 修改答辩
     */
    @Log(title = "答辩", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody TbReply tbReply)
    {
        return toAjax(tbReplyService.updateTbReply(tbReply));
    }

    /**
     * 删除答辩
     */
    @Log(title = "答辩", businessType = BusinessType.DELETE)
	@DeleteMapping("delById/{replyIds}")
    public AjaxResult remove(@PathVariable Integer[] replyIds)
    {
        return toAjax(tbReplyService.deleteTbReplyByReplyIds(replyIds));
    }
}
